/*
 * @Date: 2023-12-18 17:56:34
 * @LastEditors: 玄绮 shijiahansi@qq.com
 * @LastEditTime: 2024-01-27 19:08:44
 * @FilePath: \server\src\test\codepage.cpp
 */
#ifdef _WIN32
#    include <Windows.h>
#    include <iostream>

int main() {
    // 获取控制台输出的句柄
    HANDLE hConsoleOut = GetStdHandle(STD_OUTPUT_HANDLE);
    HANDLE hConsoleIn  = GetStdHandle(STD_INPUT_HANDLE);

    // 获取控制台的输出代码页（Code Page）
    UINT codePage = GetConsoleOutputCP();

    // 输出获取到的代码页
    std::cout << "Console Code Page: " << codePage << std::endl;

    return 0;
}
#elif __linux__
#    include <iostream>
#    include <langinfo.h>

int main() {
    // 使用 nl_langinfo 获取字符编码
    const char* encoding = nl_langinfo(CODESET);

    std::cout << "Character encoding: " << encoding << std::endl;

    return 0;
}

#else

#    include <cstdlib>
#    include <iostream>

int main() {
    // 使用 getenv 获取环境变量，检查 LC_CTYPE 变量
    const char* lcType = std::getenv("LC_CTYPE");

    if (lcType) {
        std::cout << "LC_CTYPE environment variable: " << lcType << std::endl;
    }
    else {
        std::cerr << "LC_CTYPE environment variable not found." << std::endl;
    }

    return 0;
}

#endif